home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / 8080bw.c < prev    next >
C/C++ Source or Header  |  2000-05-22  |  13KB  |  652 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11. #include "artwork.h"
  12.  
  13. static int use_tmpbitmap;
  14. static int flipscreen;
  15. static int screen_red;
  16. static int screen_red_enabled;        /* 1 for games that can turn the screen red */
  17. static int redraw_screen;
  18. static int color_map_select;
  19. static int background_color;
  20.  
  21. static int overlay_type;    /* 0=none, 1=geometric, 2=file */
  22. static const void *init_overlay;
  23.  
  24. static mem_write_handler videoram_w_p;
  25. static void (*vh_screenrefresh_p)(struct osd_bitmap *bitmap,int full_refresh);
  26. static void (*plot_pixel_p)(int x, int y, int col);
  27.  
  28. static WRITE_HANDLER( bw_videoram_w );
  29. static WRITE_HANDLER( schaser_videoram_w );
  30. static WRITE_HANDLER( lupin3_videoram_w );
  31. static WRITE_HANDLER( polaris_videoram_w );
  32. static WRITE_HANDLER( invadpt2_videoram_w );
  33. static WRITE_HANDLER( astinvad_videoram_w );
  34. static WRITE_HANDLER( spaceint_videoram_w );
  35. static WRITE_HANDLER( helifire_videoram_w );
  36.  
  37. static void vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  38. static void seawolf_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  39. static void blueshrk_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  40. static void desertgu_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  41. static void phantom2_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  42.  
  43. static void plot_pixel_8080 (int x, int y, int col);
  44. static void plot_pixel_8080_tmpbitmap (int x, int y, int col);
  45.  
  46. /* smoothed pure colors, overlays are not so contrasted */
  47.  
  48. #define RED                0xff,0x20,0x20,OVERLAY_DEFAULT_OPACITY
  49. #define GREEN             0x20,0xff,0x20,OVERLAY_DEFAULT_OPACITY
  50. #define YELLOW            0xff,0xff,0x20,OVERLAY_DEFAULT_OPACITY
  51. #define CYAN            0x20,0xff,0xff,OVERLAY_DEFAULT_OPACITY
  52.  
  53. #define    END  {{ -1, -1, -1, -1}, 0,0,0,0}
  54.  
  55.  
  56. static const struct artwork_element invaders_overlay[]=
  57. {
  58.     {{  16,  71,   0, 255}, GREEN },
  59.     {{   0,  15,  16, 133}, GREEN },
  60.     {{ 192, 223,   0, 255}, RED   },
  61.     END
  62. };
  63.  
  64. //static const struct artwork_element invdpt2m_overlay[]=
  65. //{
  66. //    {{  16,  71,   0, 255}, GREEN  },
  67. //    {{   0,  15,  16, 133}, GREEN  },
  68. //    {{  72, 191,   0, 255}, YELLOW },
  69. //    {{ 192, 223,   0, 255}, RED    },
  70. //    END
  71. //};
  72.  
  73. static const struct artwork_element invrvnge_overlay[]=
  74. {
  75.     {{   0,  71,   0, 255}, GREEN },
  76.     {{ 192, 223,   0, 255}, RED   },
  77.     END
  78. };
  79.  
  80. static const struct artwork_element invad2ct_overlay[]=
  81. {
  82.     {{     0,  47,   0, 255}, YELLOW },
  83.     {{    25,  70,   0, 255}, GREEN  },
  84.     {{    48, 139,   0, 255}, CYAN   },
  85.     {{ 117, 185,   0, 255}, GREEN  },
  86.     {{ 163, 231,   0, 255}, YELLOW },
  87.     {{ 209, 255,   0, 255}, RED    },
  88.     END
  89. };
  90.  
  91.  
  92. void init_8080bw(void)
  93. {
  94.     videoram_w_p = bw_videoram_w;
  95.     vh_screenrefresh_p = vh_screenrefresh;
  96.     use_tmpbitmap = 0;
  97.     screen_red_enabled = 0;
  98.     overlay_type = 0;
  99.     color_map_select = 0;
  100.     flipscreen = 0;
  101. }
  102.  
  103. void init_invaders(void)
  104. {
  105.     init_8080bw();
  106.     init_overlay = invaders_overlay;
  107.     overlay_type = 1;
  108. }
  109.  
  110. void init_invaddlx(void)
  111. {
  112.     init_8080bw();
  113.     //init_overlay = invdpt2m_overlay;
  114.     //overlay_type = 1;
  115. }
  116.  
  117. void init_invrvnge(void)
  118. {
  119.     init_8080bw();
  120.     init_overlay = invrvnge_overlay;
  121.     overlay_type = 1;
  122. }
  123.  
  124. void init_invad2ct(void)
  125. {
  126.     init_8080bw();
  127.     init_overlay = invad2ct_overlay;
  128.     overlay_type = 1;
  129. }
  130.  
  131. void init_schaser(void)
  132. {
  133.     init_8080bw();
  134.     videoram_w_p = schaser_videoram_w;
  135.     background_color = 2;    /* blue */
  136. }
  137.  
  138. void init_rollingc(void)
  139. {
  140.     init_8080bw();
  141.     videoram_w_p = schaser_videoram_w;
  142.     background_color = 0;    /* black */
  143. }
  144.  
  145. void init_helifire(void)
  146. {
  147.     init_8080bw();
  148.     videoram_w_p = helifire_videoram_w;
  149. }
  150.  
  151. void init_polaris(void)
  152. {
  153.     init_8080bw();
  154.     videoram_w_p = polaris_videoram_w;
  155. }
  156.  
  157. void init_lupin3(void)
  158. {
  159.     init_8080bw();
  160.     videoram_w_p = lupin3_videoram_w;
  161.     background_color = 0;    /* black */
  162. }
  163.  
  164. void init_invadpt2(void)
  165. {
  166.     init_8080bw();
  167.     videoram_w_p = invadpt2_videoram_w;
  168.     screen_red_enabled = 1;
  169. }
  170.  
  171. void init_seawolf(void)
  172. {
  173.     init_8080bw();
  174.     vh_screenrefresh_p = seawolf_vh_screenrefresh;
  175.     use_tmpbitmap = 1;
  176. }
  177.  
  178. void init_blueshrk(void)
  179. {
  180.     init_8080bw();
  181.     vh_screenrefresh_p = blueshrk_vh_screenrefresh;
  182.     use_tmpbitmap = 1;
  183. }
  184.  
  185. void init_desertgu(void)
  186. {
  187.     init_8080bw();
  188.     vh_screenrefresh_p = desertgu_vh_screenrefresh;
  189.     use_tmpbitmap = 1;
  190. }
  191.  
  192. void init_astinvad(void)
  193. {
  194.     init_8080bw();
  195.     videoram_w_p = astinvad_videoram_w;
  196.     screen_red_enabled = 1;
  197. }
  198.  
  199. void init_spaceint(void)
  200. {
  201.     init_8080bw();
  202.     videoram_w_p = spaceint_videoram_w;
  203. }
  204.  
  205. void init_spcenctr(void)
  206. {
  207.     extern struct GameDriver driver_spcenctr;
  208.  
  209.     init_8080bw();
  210.     init_overlay = driver_spcenctr.name;
  211.     overlay_type = 2;
  212. }
  213.  
  214. void init_phantom2(void)
  215. {
  216.     init_8080bw();
  217.     vh_screenrefresh_p = phantom2_vh_screenrefresh;
  218.     use_tmpbitmap = 1;
  219. }
  220.  
  221.  
  222. int invaders_vh_start(void)
  223. {
  224.     /* create overlay if one of was specified in init_X */
  225.     if (overlay_type)
  226.     {
  227.         int start_pen;
  228.         int max_pens;
  229.  
  230.  
  231.         start_pen = 2;
  232.         max_pens = Machine->drv->total_colors-start_pen;
  233.  
  234.         if (overlay_type == 1)
  235.             overlay_create((const struct artwork_element *)init_overlay, start_pen, max_pens);
  236.         else
  237.             overlay_load((const char *)init_overlay, start_pen, max_pens);
  238.     }
  239.  
  240.     if (use_tmpbitmap && (generic_bitmapped_vh_start() != 0))
  241.         return 1;
  242.  
  243.     if (use_tmpbitmap)
  244.     {
  245.         plot_pixel_p = plot_pixel_8080_tmpbitmap;
  246.     }
  247.     else
  248.     {
  249.         plot_pixel_p = plot_pixel_8080;
  250.     }
  251.  
  252.     /* make sure that the screen matches the videoram, this fixes invad2ct */
  253.     redraw_screen = 1;
  254.  
  255.     return 0;
  256. }
  257.  
  258.  
  259. void invaders_vh_stop(void)
  260. {
  261.     if (use_tmpbitmap)  generic_bitmapped_vh_stop();
  262. }
  263.  
  264.  
  265. void invaders_flipscreen_w(int data)
  266. {
  267.     if (data != color_map_select)
  268.     {
  269.         color_map_select = data;
  270.         redraw_screen = 1;
  271.     }
  272.  
  273.     if (input_port_3_r(0) & 0x01)
  274.     {
  275.         if (data != flipscreen)
  276.         {
  277.             flipscreen = data;
  278.             redraw_screen = 1;
  279.         }
  280.     }
  281. }
  282.  
  283. void sheriff_flipscreen_w(int data)
  284. {
  285.     if (data != flipscreen)
  286.     {
  287.         flipscreen = data;
  288.         redraw_screen = 1;
  289.     }
  290. }
  291.  
  292.  
  293. void invaders_screen_red_w(int data)
  294. {
  295.     if (screen_red_enabled && (data != screen_red))
  296.     {
  297.         screen_red = data;
  298.         redraw_screen = 1;
  299.     }
  300. }
  301.  
  302.  
  303. static void plot_pixel_8080 (int x, int y, int col)
  304. {
  305.     if (flipscreen)
  306.     {
  307.         x = 255-x;
  308.         y = 223-y;
  309.     }
  310.  
  311.     plot_pixel(Machine->scrbitmap,x,y,Machine->pens[col]);
  312. }
  313.  
  314. static void plot_pixel_8080_tmpbitmap (int x, int y, int col)
  315. {
  316.     if (flipscreen)
  317.     {
  318.         x = 255-x;
  319.         y = 223-y;
  320.     }
  321.  
  322.     plot_pixel(tmpbitmap,x,y,Machine->pens[col]);
  323. }
  324.  
  325. INLINE void plot_byte(int x, int y, int data, int fore_color, int back_color)
  326. {
  327.     int i;
  328.  
  329.     for (i = 0; i < 8; i++)
  330.     {
  331.         plot_pixel_p (x, y, (data & 0x01) ? fore_color : back_color);
  332.  
  333.         x++;
  334.         data >>= 1;
  335.     }
  336. }
  337.  
  338.  
  339. WRITE_HANDLER( invaders_videoram_w )
  340. {
  341.     videoram_w_p(offset, data);
  342. }
  343.  
  344.  
  345. static WRITE_HANDLER( bw_videoram_w )
  346. {
  347.     int x,y;
  348.  
  349.     videoram[offset] = data;
  350.  
  351.     y = offset / 32;
  352.     x = 8 * (offset % 32);
  353.  
  354.     plot_byte(x, y, data, 1, 0);
  355. }
  356.  
  357. static WRITE_HANDLER( schaser_videoram_w )
  358. {
  359.     int x,y,col;
  360.  
  361.     videoram[offset] = data;
  362.  
  363.     y = offset / 32;
  364.     x = 8 * (offset % 32);
  365.  
  366.     col = colorram[offset & 0x1f1f] & 0x07;
  367.  
  368.     plot_byte(x, y, data, col, background_color);
  369. }
  370.  
  371. static WRITE_HANDLER( lupin3_videoram_w )
  372. {
  373.     int x,y,col;
  374.  
  375.     videoram[offset] = data;
  376.  
  377.     y = offset / 32;
  378.     x = 8 * (offset % 32);
  379.  
  380.     col = ~colorram[offset & 0x1f1f] & 0x07;
  381.  
  382.     plot_byte(x, y, data, col, background_color);
  383. }
  384.  
  385. static WRITE_HANDLER( polaris_videoram_w )
  386. {
  387.     int x,y,back_color,foreground_color;
  388.  
  389.     videoram[offset] = data;
  390.  
  391.     y = offset / 32;
  392.     x = 8 * (offset % 32);
  393.  
  394.     /* for the background color, bit 0 if the map PROM is connected to blue gun.
  395.        red is 0 */
  396.  
  397.     back_color = (memory_region(REGION_PROMS)[(((y+32)/8)*32) + (x/8)] & 1) ? 6 : 4;
  398.     foreground_color = ~colorram[offset & 0x1f1f] & 0x07;
  399.  
  400.     plot_byte(x, y, data, foreground_color, back_color);
  401. }
  402.  
  403. static WRITE_HANDLER( helifire_videoram_w )
  404. {
  405.     int x,y,back_color,foreground_color;
  406.  
  407.     videoram[offset] = data;
  408.  
  409.     y = offset / 32;
  410.     x = 8 * (offset % 32);
  411.  
  412.     back_color = 0;
  413.     foreground_color = colorram[offset] & 0x07;
  414.  
  415.     if (x < 0x78)
  416.     {
  417.         back_color = 4;    /* blue */
  418.     }
  419.  
  420.     plot_byte(x, y, data, foreground_color, back_color);
  421. }
  422.  
  423.  
  424. WRITE_HANDLER( schaser_colorram_w )
  425. {
  426.     int i;
  427.  
  428.  
  429.     offset &= 0x1f1f;
  430.  
  431.     colorram[offset] = data;
  432.  
  433.     /* redraw region with (possibly) changed color */
  434.     for (i = 0; i < 8; i++, offset += 0x20)
  435.     {
  436.         videoram_w_p(offset, videoram[offset]);
  437.     }
  438. }
  439.  
  440. READ_HANDLER( schaser_colorram_r )
  441. {
  442.     return colorram[offset & 0x1f1f];
  443. }
  444.  
  445.  
  446. WRITE_HANDLER( helifire_colorram_w )
  447. {
  448.     colorram[offset] = data;
  449.  
  450.     /* redraw region with (possibly) changed color */
  451.     videoram_w_p(offset, videoram[offset]);
  452. }
  453.  
  454.  
  455. /***************************************************************************
  456.  
  457.   Draw the game screen in the given osd_bitmap.
  458.   Do NOT call osd_update_display() from this function, it will be called by
  459.   the main emulation engine.
  460.  
  461. ***************************************************************************/
  462. void invaders_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  463. {
  464.     vh_screenrefresh_p(bitmap, full_refresh);
  465. }
  466.  
  467.  
  468. static void vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  469. {
  470.     if (palette_recalc() || redraw_screen || (full_refresh && !use_tmpbitmap))
  471.     {
  472.         int offs;
  473.  
  474.         for (offs = 0;offs < videoram_size;offs++)
  475.             videoram_w_p(offs, videoram[offs]);
  476.  
  477.         redraw_screen = 0;
  478.     }
  479.  
  480.  
  481.     if (use_tmpbitmap)
  482.         copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  483. }
  484.  
  485.  
  486. static void draw_sight(int x_center, int y_center)
  487. {
  488.     int x,y;
  489.  
  490.  
  491.     if (x_center<2)   x_center=2;
  492.     if (x_center>253) x_center=253;
  493.  
  494.     if (y_center<2)   y_center=2;
  495.     if (y_center>253) y_center=253;
  496.  
  497.     for(y = y_center-10; y < y_center+11; y++)
  498.         if((y >= 0) && (y < 256))
  499.             plot_pixel_8080(x_center,y,1);
  500.  
  501.     for(x = x_center-20; x < x_center+21; x++)
  502.         if((x >= 0) && (x < 256))
  503.             plot_pixel_8080(x,y_center,1);
  504. }
  505.  
  506.  
  507. static void seawolf_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  508. {
  509.     /* update the bitmap (and erase old cross) */
  510.     vh_screenrefresh(bitmap, 1);
  511.  
  512.     draw_sight(((input_port_0_r(0) & 0x1f) * 8) + 4, 31);
  513. }
  514.  
  515. static void blueshrk_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  516. {
  517.     /* update the bitmap (and erase old cross) */
  518.     vh_screenrefresh(bitmap, 1);
  519.  
  520.     draw_sight(((input_port_0_r(0) & 0x7f) * 2) - 12, 31);
  521. }
  522.  
  523. static void desertgu_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  524. {
  525.     /* update the bitmap (and erase old cross) */
  526.     vh_screenrefresh(bitmap, 1);
  527.  
  528.     draw_sight(((input_port_0_r(0) & 0x7f) * 2) - 30,
  529.                ((input_port_2_r(0) & 0x7f) * 2) - 30);
  530. }
  531.  
  532. static void phantom2_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  533. {
  534.     unsigned char *clouds;
  535.     int x, y;
  536.  
  537.  
  538.     /* update the bitmap */
  539.     vh_screenrefresh(bitmap, 1);
  540.  
  541.  
  542.     /* draw the clouds */
  543.     clouds = memory_region(REGION_PROMS);
  544.  
  545.     for (y = 0; y < 128; y++)
  546.     {
  547.         unsigned char *offs = &memory_region(REGION_PROMS)[y * 0x10];
  548.  
  549.         for (x = 0; x < 128; x++)
  550.         {
  551.             if (offs[x >> 3] & (1 << (x & 0x07)))
  552.             {
  553.                 plot_pixel_8080(x*2,   y*2,   1);
  554.                 plot_pixel_8080(x*2+1, y*2,   1);
  555.                 plot_pixel_8080(x*2,   y*2+1, 1);
  556.                 plot_pixel_8080(x*2+1, y*2+1, 1);
  557.             }
  558.         }
  559.     }
  560. }
  561.  
  562.  
  563. void invadpt2_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  564. {
  565.     int i;
  566.  
  567.  
  568.     for (i = 0;i < Machine->drv->total_colors;i++)
  569.     {
  570.         /* this bit arrangment is a little unusual but are confirmed by screen shots */
  571.  
  572.         *(palette++) = 0xff * ((i >> 0) & 1);
  573.         *(palette++) = 0xff * ((i >> 2) & 1);
  574.         *(palette++) = 0xff * ((i >> 1) & 1);
  575.     }
  576. }
  577.  
  578. void helifire_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  579. {
  580.     int i;
  581.  
  582.  
  583.     for (i = 0;i < Machine->drv->total_colors;i++)
  584.     {
  585.         *(palette++) = 0xff * ((i >> 0) & 1);
  586.         *(palette++) = 0xff * ((i >> 1) & 1);
  587.         *(palette++) = 0xff * ((i >> 2) & 1);
  588.     }
  589. }
  590.  
  591.  
  592. static WRITE_HANDLER( invadpt2_videoram_w )
  593. {
  594.     int x,y,col;
  595.  
  596.     videoram[offset] = data;
  597.  
  598.     y = offset / 32;
  599.     x = 8 * (offset % 32);
  600.  
  601.     /* 32 x 32 colormap */
  602.     if (!screen_red)
  603.         col = memory_region(REGION_PROMS)[(color_map_select ? 0x400 : 0 ) + (((y+32)/8)*32) + (x/8)] & 7;
  604.     else
  605.         col = 1;    /* red */
  606.  
  607.     plot_byte(x, y, data, col, 0);
  608. }
  609.  
  610. static WRITE_HANDLER( astinvad_videoram_w )
  611. {
  612.     int x,y,col;
  613.  
  614.     videoram[offset] = data;
  615.  
  616.     y = offset / 32;
  617.     x = 8 * (offset % 32);
  618.  
  619.     if (!screen_red)
  620.     {
  621.         if (flipscreen)
  622.             col = memory_region(REGION_PROMS)[((y+32)/8)*32+(x/8)] >> 4;
  623.         else
  624.             col = memory_region(REGION_PROMS)[(31-y/8)*32+(31-x/8)] & 0x0f;
  625.     }
  626.     else
  627.         col = 1; /* red */
  628.  
  629.     plot_byte(x, y, data, col, 0);
  630. }
  631.  
  632. static WRITE_HANDLER( spaceint_videoram_w )
  633. {
  634.     int i,x,y,col;
  635.  
  636.     videoram[offset] = data;
  637.  
  638.     y = 8 * (offset / 256);
  639.     x = offset % 256;
  640.  
  641.     /* this is wrong */
  642.     col = memory_region(REGION_PROMS)[(y/16)+16*((x+16)/32)];
  643.  
  644.     for (i = 0; i < 8; i++)
  645.     {
  646.         plot_pixel_p(x, y, (data & 0x01) ? col : 0);
  647.  
  648.         y++;
  649.         data >>= 1;
  650.     }
  651. }
  652.